require.config({
	shim:{
        'calendar':{exports:'calendar'}
    },
    paths : {
        //"vue":"lib/vue",
        "jquery":"lib/jquery",
        "cmd":"cmd",
        "calendar":"lib/datepicker/WdatePicker",
    }
});

require(['jquery','cmd','calendar'],function($){

//get top menu
var token = detectToken();
//dtu_id
var dtuID = window.location.search.split("=")[1];

//默认加载交互日志列表
$.vloading.show();
$.ajax({ 
    type:"post", 
    url:urls.checkjhLogs, 
    data: {token:token,pageNow:1,pageSize:20,dtu_id:dtuID}, 
    dataType: 'json', 
    async : true, 
    success:function(result){ 
        var tableContentHtml = '';
        $.vloading.remove();
        if(result.code=="1"){
            if(result.data.records.length==0){
                $(".showtableContent").html('<p class="txtc" style="padding:19px 0;font-size:16px;border-right:1px solid #e9e9e9;border-bottom:1px solid #e9e9e9;">暂无数据</p>');
            }else{
                for(var i=0;i<result.data.records.length;i++){
                    tableContentHtml +='<div class="tableTReach clearfix">\n\
                      <div class="tablecommoncel-1 tableTBdpoint fl"><i data-id="'+result.data.records[i].id+'" class="xwl i-checkno"></i></div>\n\
                      <div class="tablecommoncel-2 tableTBdZH fl oellipsis">'+result.data.records[i].dtu_id+'</div>\n\
                      <div class="tablecommoncel-3 tableTBdDTU fl">'+result.data.records[i].model+'</div>\n\
                      <div class="tablecommoncel-4 tableTBdMK fl oellipsis">'+result.data.records[i].command_type+'</div>\n\
                      <div class="tablecommoncel-5 tableTBdFF fl">'+result.data.records[i].create_date+'</div>\n\
                      <div class="tablecommoncel-6 tableTBdIP fl oellipsis">'+result.data.records[i].command_content+'</div>\n\
                    </div>';
                }
                $(".showtableContent").html(tableContentHtml);
            }

        }else{
            $.flytip("服务器繁忙，请稍后再试");
        }
        //总页数
        $(".allpagesNums").html(result.data.pageCount);
        //总记录数
        $(".allRecord").html(result.data.rowCount);
        pageNav.go(1,result.data.pageCount);
        pageNav.fn = function(p,pn){
                if($("#timerfilterBtn").attr("data-coding")==0){
                    getTableContentHtml(p);
                    return;
                }
        };
    } 
});

var getTableContentHtml = function(curNums){
    var dtu_id = dtuID;
    var mode = $("#eventIsread").val();
    var command_type = $("#eventOrdertypes").val();
    var start_date = $("#startDate").val();
    var end_date =$("#endDate").val();
    var pageNow = curNums;
    var pageSize = 20;
    $.vloading.show();
    $.ajax({ 
        type:"post", 
        url:urls.checkjhLogs, 
        data: {token:token,pageNow:pageNow,pageSize:20,dtu_id:dtu_id,mode:mode,command_type:command_type,start_date:start_date,end_date:end_date}, 
        dataType: 'json', 
        async : true, 
        success:function(result){ 
            var tableContentHtml = '';
            $.vloading.remove();
            if(result.code=="1"){
                if(result.data.records.length==0){
                    $(".showtableContent").html('<p class="txtc" style="padding:19px 0;font-size:16px;border-right:1px solid #e9e9e9;border-bottom:1px solid #e9e9e9;">暂无数据</p>');
                }else{
                    for(var i=0;i<result.data.records.length;i++){
                        tableContentHtml +='<div class="tableTReach clearfix">\n\
                          <div class="tablecommoncel-1 tableTBdpoint fl"><i data-id="'+result.data.records[i].id+'" class="xwl i-checkno"></i></div>\n\
                          <div class="tablecommoncel-2 tableTBdZH fl oellipsis">'+result.data.records[i].dtu_id+'</div>\n\
                          <div class="tablecommoncel-3 tableTBdDTU fl">'+result.data.records[i].model+'</div>\n\
                          <div class="tablecommoncel-4 tableTBdMK fl oellipsis">'+result.data.records[i].command_type+'</div>\n\
                          <div class="tablecommoncel-5 tableTBdFF fl">'+result.data.records[i].create_date+'</div>\n\
                          <div class="tablecommoncel-6 tableTBdIP fl oellipsis">'+result.data.records[i].command_content+'</div>\n\
                        </div>';
                    }
                    $(".showtableContent").html(tableContentHtml);
                }

            }else{
                $.flytip("服务器繁忙，请稍后再试");
            }
            //总页数
            $(".allpagesNums").html(result.data.pageCount);
            //总记录数
            $(".allRecord").html(result.data.rowCount);
        } 
    });

} 
//查询
$("#timerfilterBtn").on("click",function(){
    $("#timerfilterBtn").attr("data-coding",1);
    var dtu_id = dtuID;
    var mode = $("#eventIsread").val();
    var command_type = $("#eventOrdertypes").val();
    var start_date = $("#startDate").val();
    var end_date =$("#endDate").val();
    var pageNow = 1;
    var pageSize = 20;
    $.vloading.show();
    $.ajax({ 
        type:"post", 
        url:urls.checkjhLogs, 
        data: {token:token,pageNow:pageNow,pageSize:20,dtu_id:dtu_id,mode:mode,command_type:command_type,start_date:start_date,end_date:end_date}, 
        dataType: 'json', 
        async : true, 
        success:function(result){ 
            var tableContentHtml = '';
            $.vloading.remove();
            if(result.code=="1"){
                if(result.data.records.length==0){
                    $(".showtableContent").html('<p class="txtc" style="padding:19px 0;font-size:16px;border-right:1px solid #e9e9e9;border-bottom:1px solid #e9e9e9;">暂无数据</p>');
                }else{
                    for(var i=0;i<result.data.records.length;i++){
                        tableContentHtml +='<div class="tableTReach clearfix">\n\
                          <div class="tablecommoncel-1 tableTBdpoint fl"><i data-id="'+result.data.records[i].id+'" class="xwl i-checkno"></i></div>\n\
                          <div class="tablecommoncel-2 tableTBdZH fl oellipsis">'+result.data.records[i].dtu_id+'</div>\n\
                          <div class="tablecommoncel-3 tableTBdDTU fl">'+result.data.records[i].model+'</div>\n\
                          <div class="tablecommoncel-4 tableTBdMK fl oellipsis">'+result.data.records[i].command_type+'</div>\n\
                          <div class="tablecommoncel-5 tableTBdFF fl">'+result.data.records[i].create_date+'</div>\n\
                          <div class="tablecommoncel-6 tableTBdIP fl oellipsis">'+result.data.records[i].command_content+'</div>\n\
                        </div>';
                    }
                    $(".showtableContent").html(tableContentHtml);
                }

            }else{
                $.flytip("服务器繁忙，请稍后再试");
            }

            //总页数
            $(".allpagesNums").html(result.data.pageCount);
            //总记录数
            $(".allRecord").html(result.data.rowCount);
            pageNav.go(1,result.data.pageCount);
            pageNav.fn = function(p,pn){
                if($("#timerfilterBtn").attr("data-coding")==1){
                    getTableContentHtml(p);
                    return;
                }
            };

        } 
    });



})









//$.flytip("zhowdom");$.vloading.show();$.vloading.remove();


//============系统管理模块一级二级三级按钮菜单权限控制 START ============
getOnelayerMenu();
//三级菜单控制显示(设备详情页的二级菜单实际上是一个三级菜单，特殊处理)
$.ajax({ 
    type:"post", 
    url:urls.getMachineBtns, 
    data: {token:localStorage.getItem("token"),id:201}, 
    dataType: 'json', 
    async : true, 
    success:function(result){
        var tableTopbarlHtml = '';
        for(var i=0;i<result.data.length;i++){
            var forinVals2 = result.data[i].id;
            switch (forinVals2)
            {
            case 205:
              if(result.data[i].ishide==1){
                tableTopbarlHtml +='<a href="machineDetails.html?dtuid='+dtuID+'" data-id="'+result.data[i].id+'" id="eventsDel" herf="javascript:;">'+result.data[i].name+'</a>';
              }
              break;
            case 206:
              if(result.data[i].ishide==1){
                tableTopbarlHtml +='<a href="morePara-maintainCoefficient.html?dtuid='+dtuID+'" data-id="'+result.data[i].id+'" id="eventsDel" herf="javascript:;">'+result.data[i].name+'</a>';
              }
              break;
            case 207:
              if(result.data[i].ishide==1){
                tableTopbarlHtml +='<a class="cur" href="interactiveLog.html?dtuid='+dtuID+'" data-id="'+result.data[i].id+'" id="eventsDel" herf="javascript:;">'+result.data[i].name+'</a>';
              }
              break;
            case 208:
              if(result.data[i].ishide==1){
                tableTopbarlHtml +='<a href="#" data-id="'+result.data[i].id+'" id="eventsDel" herf="javascript:;">'+result.data[i].name+'</a>';
              }
              break;
            } 
        }
        $(".mianshowbpt-r").html(tableTopbarlHtml);
    } 
});    
getThreelayerMenu(207);
//============系统管理模块一级二级三级按钮菜单权限控制 END ============



//=========批量/单个删除START=========
//单选与全选
$(".tableTHpoint").click(function(){
    $(this).find("i").toggleClass("i-checked");
    if($(this).find("i").hasClass("i-checked")){
        $(".tableTReach .tablecommoncel-1 i").addClass("i-checked");
    }else{
        $(".tableTReach .tablecommoncel-1 i").removeClass("i-checked");
    }
})
$("body").on("click",".tableTReach .tablecommoncel-1",function(){
    $(this).find("i").toggleClass("i-checked");
})

$("#eventsDel").on("click",function(){
    var hadChoosedNums = document.querySelectorAll(".tableTReach .tablecommoncel-1 .i-checked");
    var hadChoosed_Arr = [];
    for(var i=0;i<hadChoosedNums.length;i++){
        hadChoosed_Arr.push(hadChoosedNums[i].attributes[0].value);
    }
    if(hadChoosedNums.length==0){
        $.flytip("请选择要删除的记录");
        return;
    }else{
        $.ajax({ 
            type:"post", 
            url:urls.deljhLogs, 
            data: {token:token,ids:hadChoosed_Arr.join(",")}, 
            dataType: 'json', 
            async : true, 
            success:function(result){
                $("i.i-checked").parent(".tableTBdpoint").parent(".tableTReach").remove();
                if($(".showtableContent .tableTReach").length==0){
                    window.location.reload();
                }

            } 
        });        
    }

})
//=========批量/单个删除END=========

//个人中心下拉
$("#showmyAccountMenu").toggle(
    function(){$("#toggleshowmenu").show();},
    function(){$("#toggleshowmenu").hide();}
);











//req.js end
})